package com.sun.proxy;

import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * @Author: Suncl
 * @Date: 2023/3/19 11:07
 */
public class ProxyTest {

    @Test
    public void test1(){
        try {
            Class<?> proxyClass = Proxy.getProxyClass(ProxyTest.class.getClassLoader(), HelloWorld.class);

            Constructor<?> constructor = proxyClass.getConstructor(InvocationHandler.class);

            MyInvocationHandler myInvocationHandler = new MyInvocationHandler(new HelloWorldImpl());

            HelloWorld instance = (HelloWorld) constructor.newInstance(myInvocationHandler);

            instance.sayHello();



        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
